package com.example.yuejian11.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.blankj.utilcode.util.ActivityUtils;
import com.bumptech.glide.Glide;
import com.example.yuejian11.R;
import com.example.yuejian11.activity.MasterActivityDetail;
import com.example.yuejian11.bean.ActivityListEntity;
import com.example.yuejian11.bean.MasterEntity;
import com.example.yuejian11.common.Url;
import com.yuyh.easyadapter.AdapterImageLoader;
import com.yuyh.easyadapter.recyclerview.EasyRVAdapter;
import com.yuyh.easyadapter.recyclerview.EasyRVHolder;

import java.util.List;

public class MainMasterAdapter extends EasyRVAdapter<MasterEntity> {

    public MainMasterAdapter(Context context, List<MasterEntity> list, int... layoutIds) {
        super(context, list, layoutIds);
    }

    @Override
    protected void onBindData(EasyRVHolder viewHolder, final int position, final MasterEntity item) {
        viewHolder.setText(R.id.title, item.getName());
        //viewHolder.setText(R.id.starno, item.getName());
        // 自定义点击可覆盖父类的setOnItemClickListener
        viewHolder.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent =new Intent(v.getContext(),MasterActivityDetail.class);
                intent.putExtra("mid",item.getId());
                ActivityUtils.startActivity(intent);

            }
        });
        viewHolder.setImageUrl(R.id.img, Url.imgUrl+item.getPic());
    }

    @Override
    public int getLayoutIndex(int position, MasterEntity item) {
        return 0;
    }
    @Override
    public AdapterImageLoader.ImageLoader getImageLoader() {
        // 重写该方法，以替换全局初始化的ImageLoader
        return new AdapterImageLoader.ImageLoader() {
            @Override
            public void loadImage(Context context, String url, ImageView view) {
                Glide.with(context)
                        .load(url)
                        .into(view);
            }
        };
    }
}